/**
 * 
 */
package com.lemote.action.order;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lemote.action.BaseAction;
import com.lemote.core.PropertyFilter;
import com.lemote.entity.OrderEntity;
import com.lemote.entity.ShowEntity;
import com.lemote.exception.AppException;
import com.lemote.service.order.OrderService;
import com.lemote.service.order.ShowEntityService;

/**
 * @author wuhui
 *
 * 上午11:15:47
 */
@Service("showEntityAction")
public class ShowEntityAction extends BaseAction<ShowEntity, ShowEntityService> {

	private ShowEntity showEntity;
	
	private OrderService orderService;
	
	@Override
	public String delete() throws AppException {
		
		return null;
	}

	
	@Override
	public String input() throws AppException {
		
		return null;
	}

	
	@Override
	public String list() throws AppException {
		List<PropertyFilter> filters = new ArrayList<PropertyFilter>();
		PropertyFilter filter = new PropertyFilter("EQS_status", "1");
		filters.add(filter);
		List<OrderEntity> orders = orderService.getList(filters);
		Random random = new Random(); 
		if (orders!=null&&orders.size()>0) {
			int index = random.nextInt(orders.size());
			showEntity = entityService.get("orderNo", orders.get(index).getOrderNo());
		}
		return SUCCESS;
	}

	
	@Override
	public void prepareModel() throws AppException {
		
		
	}

	
	@Override
	public String save() throws AppException {
		
		return null;
	}

	@Autowired
	@Override
	public void setEntityService(ShowEntityService entityService) {
		
		this.entityService = entityService;
	}

	
	@Autowired
	public void setOrderService(OrderService orderService) {
		this.orderService = orderService;
	}


	@Override
	public ShowEntity getModel() {
		
		return showEntity;
	}

}
